package cn.itsource.order.service.impl;

import cn.itsource.basic.service.BaseServiceImpl;
import cn.itsource.basic.util.AjaxResult;
import cn.itsource.basic.util.GetUserInfoUtil;
import cn.itsource.order.domain.UserAddress;
import cn.itsource.order.mapper.UserAddressMapper;
import cn.itsource.order.query.UserAddressQuery;
import cn.itsource.order.service.IUserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
//Propagation.SUPPORTS:支持别人事务
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class UserAddressServiceImpl extends BaseServiceImpl<UserAddress, UserAddressQuery> implements IUserAddressService {

    @Autowired
    private UserAddressMapper userAddressMapper;

    @Override
    public AjaxResult findByUserId() {

        //1.拿到登录user的userId
        Long userId = GetUserInfoUtil.getUserId();

        //2通过userId查询用户地址
        List<UserAddress> userAddressList =  userAddressMapper.findByUserId(userId);
        //3.返回
        return AjaxResult.createSuccess(userAddressList);
    }
}
